package ar.org.fiel.tarifasocial.om.base;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

import ar.org.fiel.tarifasocial.om.model.*;

import ar.org.fiel.tarifasocial.om.peer.*;

        

/**
 * This class was autogenerated by Torque on:
 *
 * [Mon Jun 18 20:18:58 ART 2007]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to WebReference
 */
public abstract class BaseWebReference extends BaseObject
{
    /** The Peer class */
    private static final WebReferencePeer peer =
        new WebReferencePeer();

        
    /** The value for the id field */
    private Integer id;
      
    /** The value for the name field */
    private String name;
      
    /** The value for the description field */
    private String description;
      
    /** The value for the uRL field */
    private String uRL;
  
            
    /**
     * Get the Id
     *
     * @return Integer
     */
    public Integer getId()
    {
        return id;
    }

                                              
    /**
     * Set the value of Id
     *
     * @param v new value
     */
    public void setId(Integer v) throws TorqueException
    {
    
                  if (!ObjectUtils.equals(this.id, v))
              {
            this.id = v;
            setModified(true);
        }
    
          
                                  
                  // update associated WebReferenceItem
        if (collWebReferenceItems != null)
        {
            for (int i = 0; i < collWebReferenceItems.size(); i++)
            {
                ((WebReferenceItem) collWebReferenceItems.get(i))
                    .setWebReferenceId(v);
            }
        }
                                }
          
    /**
     * Get the Name
     *
     * @return String
     */
    public String getName()
    {
        return name;
    }

                        
    /**
     * Set the value of Name
     *
     * @param v new value
     */
    public void setName(String v) 
    {
    
                  if (!ObjectUtils.equals(this.name, v))
              {
            this.name = v;
            setModified(true);
        }
    
          
              }
          
    /**
     * Get the Description
     *
     * @return String
     */
    public String getDescription()
    {
        return description;
    }

                        
    /**
     * Set the value of Description
     *
     * @param v new value
     */
    public void setDescription(String v) 
    {
    
                  if (!ObjectUtils.equals(this.description, v))
              {
            this.description = v;
            setModified(true);
        }
    
          
              }
          
    /**
     * Get the URL
     *
     * @return String
     */
    public String getURL()
    {
        return uRL;
    }

                        
    /**
     * Set the value of URL
     *
     * @param v new value
     */
    public void setURL(String v) 
    {
    
                  if (!ObjectUtils.equals(this.uRL, v))
              {
            this.uRL = v;
            setModified(true);
        }
    
          
              }
  
         
                                
            
          /**
     * Collection to store aggregation of collWebReferenceItems
     */
    protected List collWebReferenceItems;

    /**
     * Temporary storage of collWebReferenceItems to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initWebReferenceItems()
    {
        if (collWebReferenceItems == null)
        {
            collWebReferenceItems = new ArrayList();
        }
    }

        
    /**
     * Method called to associate a WebReferenceItem object to this object
     * through the WebReferenceItem foreign key attribute
     *
     * @param l WebReferenceItem
     * @throws TorqueException
     */
    public void addWebReferenceItem(WebReferenceItem l) throws TorqueException
    {
        getWebReferenceItems().add(l);
        l.setWebReference((WebReference) this);
    }

    /**
     * The criteria used to select the current contents of collWebReferenceItems
     */
    private Criteria lastWebReferenceItemsCriteria = null;
      
    /**
                   * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getWebReferenceItems(new Criteria())
                   *
     * @return the collection of associated objects
           * @throws TorqueException
           */
    public List getWebReferenceItems()
              throws TorqueException
          {
                      if (collWebReferenceItems == null)
        {
            collWebReferenceItems = getWebReferenceItems(new Criteria(10));
        }
                return collWebReferenceItems;
          }

    /**
           * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this WebReference has previously
           * been saved, it will retrieve related WebReferenceItems from storage.
     * If this WebReference is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getWebReferenceItems(Criteria criteria) throws TorqueException
    {
              if (collWebReferenceItems == null)
        {
            if (isNew())
            {
               collWebReferenceItems = new ArrayList();
            }
            else
            {
                        criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId() );
                        collWebReferenceItems = WebReferenceItemPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                            criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                            if (!lastWebReferenceItemsCriteria.equals(criteria))
                {
                    collWebReferenceItems = WebReferenceItemPeer.doSelect(criteria);
                }
            }
        }
        lastWebReferenceItemsCriteria = criteria;

        return collWebReferenceItems;
          }

    /**
           * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getWebReferenceItems(new Criteria(),Connection)
           * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getWebReferenceItems(Connection con) throws TorqueException
    {
              if (collWebReferenceItems == null)
        {
            collWebReferenceItems = getWebReferenceItems(new Criteria(10), con);
        }
        return collWebReferenceItems;
          }

    /**
           * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this WebReference has previously
           * been saved, it will retrieve related WebReferenceItems from storage.
     * If this WebReference is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getWebReferenceItems(Criteria criteria, Connection con)
            throws TorqueException
    {
              if (collWebReferenceItems == null)
        {
            if (isNew())
            {
               collWebReferenceItems = new ArrayList();
            }
            else
            {
                         criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                         collWebReferenceItems = WebReferenceItemPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                             criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                             if (!lastWebReferenceItemsCriteria.equals(criteria))
                 {
                     collWebReferenceItems = WebReferenceItemPeer.doSelect(criteria, con);
                 }
             }
         }
         lastWebReferenceItemsCriteria = criteria;

         return collWebReferenceItems;
           }

                        
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
                 * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this WebReference is new, it will return
                 * an empty collection; or if this WebReference has previously
     * been saved, it will retrieve related WebReferenceItems from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in WebReference.
     */
    protected List getWebReferenceItemsJoinSection(Criteria criteria)
        throws TorqueException
    {
                    if (collWebReferenceItems == null)
        {
            if (isNew())
            {
               collWebReferenceItems = new ArrayList();
            }
            else
            {
                              criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                              collWebReferenceItems = WebReferenceItemPeer.doSelectJoinSection(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
                                    criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                                    if (!lastWebReferenceItemsCriteria.equals(criteria))
            {
                collWebReferenceItems = WebReferenceItemPeer.doSelectJoinSection(criteria);
            }
        }
        lastWebReferenceItemsCriteria = criteria;

        return collWebReferenceItems;
                }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
                 * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this WebReference is new, it will return
                 * an empty collection; or if this WebReference has previously
     * been saved, it will retrieve related WebReferenceItems from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in WebReference.
     */
    protected List getWebReferenceItemsJoinWebReference(Criteria criteria)
        throws TorqueException
    {
                    if (collWebReferenceItems == null)
        {
            if (isNew())
            {
               collWebReferenceItems = new ArrayList();
            }
            else
            {
                              criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                              collWebReferenceItems = WebReferenceItemPeer.doSelectJoinWebReference(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
                                    criteria.add(WebReferenceItemPeer.WRI_WRF_ID, getId());
                                    if (!lastWebReferenceItemsCriteria.equals(criteria))
            {
                collWebReferenceItems = WebReferenceItemPeer.doSelectJoinWebReference(criteria);
            }
        }
        lastWebReferenceItemsCriteria = criteria;

        return collWebReferenceItems;
                }
                            


          
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(WebReferencePeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    WebReferencePeer.doInsert((WebReference) this, con);
                    setNew(false);
                }
                else
                {
                    WebReferencePeer.doUpdate((WebReference) this, con);
                }
                }

                                      
                                    if (collWebReferenceItems != null)
            {
                for (int i = 0; i < collWebReferenceItems.size(); i++)
                {
                    ((WebReferenceItem) collWebReferenceItems.get(i)).save(con);
                }
            }
                                  alreadyInSave = false;
        }
      }

                        
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key id ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setId(new Integer(((NumberKey) key).intValue()));
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setId(new Integer(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getId());
      }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public WebReference copy() throws TorqueException
    {
        return copyInto(new WebReference());
    }
  
    protected WebReference copyInto(WebReference copyObj) throws TorqueException
    {
          copyObj.setId(id);
          copyObj.setName(name);
          copyObj.setDescription(description);
          copyObj.setURL(uRL);
  
                    copyObj.setId((Integer)null);
                              
                                      
                            
        List v = getWebReferenceItems();
                            if (v != null)
        {
            for (int i = 0; i < v.size(); i++)
            {
                WebReferenceItem obj = (WebReferenceItem) v.get(i);
                copyObj.addWebReferenceItem(obj.copy());
            }
        }
        else
        {
            copyObj.collWebReferenceItems = null;
        }
                            return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public WebReferencePeer getPeer()
    {
        return peer;
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("WebReference:\n");
        str.append("Id = ")
               .append(getId())
             .append("\n");
        str.append("Name = ")
               .append(getName())
             .append("\n");
        str.append("Description = ")
               .append(getDescription())
             .append("\n");
        str.append("URL = ")
               .append(getURL())
             .append("\n");
        return(str.toString());
    }
}
